<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>上海农商还款卡绑卡</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div id="pageInTab" class="pageInTab">
				<form id="ins_cfg_info_edit_form">
					<div class="fieldset1 tabel_col clearFix">
						<div class="fieldBox col_50">
							<div class="label">客户姓名</div>
							<div class="field">
								<span >${cstNm}</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">身份证号</div>
							<div class="field">
								<span >${certNo}</span>
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">合同号</div>
							<div class="field">
								<span >${lsCntNo}</span>
							</div>
						</div>
						<div>
						 <div class="label" style="color: blue;">绑卡信息</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">开户银行</div>
							<div class="field">
								<select name="bkCd" id="bkCd" value="${bkCd}" validate="{required:true}">
									<c:if test="${bkCd == null || bkCd == ''}">
										<option value="" selected="selected">--请选择--</option>
									</c:if>
									<c:if test="${bkCd != null && bkCd != ''}">
										<option value="">--请选择--</option>
									</c:if>
									<c:forEach items="${bankList}" var="item">
										<c:if test="${item.key == bkCd}">
											<option value="${item.key}" selected="selected">${item.value}</option>
										</c:if>
										<c:if test="${item.key != bkCd}">
											<option value="${item.key}">${item.value}</option>
										</c:if>
									</c:forEach>
								</select>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
					   <div class="fieldBox col_50">
							<div class="label">银行账号</div>
							<div class="field">
								<input name="accNo" id="accNo" type="text" class="ui-textbox" value="${accNo}" validate="{number:true, maxlength:22, minlength:15}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">预留手机号</div>
							<div class="field">
								<input name="mp" id="mp" type="text" class="ui-textbox" value="${mp}" validate="{number:true, maxlength:11, minlength:11}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">验证码</div>
							<div class="field">
								<input name="verificationCode" id="verificationCode" type="text" class="ui-textbox" value="" onchange="getCode()">
							</div>
						</div>
						<div class="fieldBox col_100" style="display: none;">
							<div class="field">
								<input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
								<input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
								<input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
								<input name="certNo" id="certNo" type="text" class="ui-textbox" value="${certNo}">
								<input name="cstAccInfoId" id="cstAccInfoId" type="text" class="ui-textbox" value="${cstAccInfoId}">
								<input name="fundRasInsId" id=fundRasInsId type="text" class="ui-textbox" value="${fundRasInsId}">
								<input name="uniqueCode" id=uniqueCode type="text" class="ui-textbox" value="${uniqueCode}">
							</div>
						</div>
					</div>
					 <div id="saveInsCfgDiv" class="btnsBox">
					 <span id="msmCodeCfg" class="sq-button sq-button-round" onclick="return getVerificationCode();">获取验证码</span>
                	 <span id="saveInsCfg" class="sq-button sq-button-round " onclick="return saveInfo();">确认绑卡</span>
                	 <span id="saveInsCfgOne" class="sq-button sq-button-round flowBtn" >确认绑卡</span>
                	
                	</div>
				</form>
			</div>
		</div>
	</div>
<script type="text/javascript">
$(function () {
	initData();
	$("#saveInsCfg").hide();
	$(".flowBtn").addClass("disabled").attr("flowKey","");
});

function initData() {
    $("#ins_cfg_info_edit_form").ligerForm({
        validate: true
    });
}

function disabledInput() {
	liger.get("bkCd").setDisabled();
	liger.get("accNo").setDisabled();
	liger.get("mp").setDisabled();

}

frameElement.dialog.onOk = function () {
	saveInfo();
}
//如果获取到验证码,换卡按钮开放
function getCode(){
	 var  verificationCode =  $("#verificationCode").val();
	 if(verificationCode){
		 $("#saveInsCfg").show();
		 $("#saveInsCfgOne").hide();
	 }else{
		 $("#saveInsCfgOne").show();
		 $("#saveInsCfg").hide();
		 $(".flowBtn").addClass("disabled").attr("flowKey","");
	 }
}

//获取验证码
function getVerificationCode(){
	if($("#msmCodeCfg").attr("isSend") == '1'){
		return;
	}
	settime($("#msmCodeCfg"));
	var ligerForm = liger.get("ins_cfg_info_edit_form");
    if (!ligerForm.valid()) {
        top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
        return false; //验证不通过，不执行以下代码
    }
    var data = ligerForm.getData();
	if(!$("#bkCd").val()){
		top.$.ligerDialog.SQalert({content: "请选择开户银行！", SQ_type: "error"});
		return false;
	}
    if(!$("#accNo").val()){
        top.$.ligerDialog.SQalert({content: "银行账号不能为空，请补充！", SQ_type: "error"});
        return false;
    }
    if(!$("#mp").val()){
        top.$.ligerDialog.SQalert({content: "预留手机号不能为空，请补充！", SQ_type: "error"});
        return false;
    }
	data["bkCd"] = liger.get("bkCd").selectedValue;
	data["bkNm"] = liger.get("bkCd").selectedText;
	data["cstAccInfoId"] = $("#cstAccInfoId").val();
    data["prjId"] = $("#prjId").val();
    data["cstId"] = $("#cstId").val();
    data["cstNm"] = $("#cstNm").val();
    data["fundRasInsId"] = $("#fundRasInsId").val();
    data["certNo"] = $("#certNo").val();
	data["accNo"] =  $("#accNo").val();
    data["mp"] = $("#mp").val();
	var wait_dialog;
    var url = '<%=path%>/institution/shnsbank/getVerificationCode.do';
    $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        },
        success: function (msg) {
			wait_dialog.close();
            if (msg.success == 1) {
                $("#uniqueCode").val(msg.data.uniqueCode);
                // top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
				UIUtils.alertSuccessHold1(msg.info);
            } else {
                // top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
				UIUtils.alertErrorHold1(msg.info);
            }
        },
        error:function () {
            // UIUtils.alertError("验证码发送失败");
			UIUtils.alertErrorHold1("验证码发送失败");
        }
    });
}

var countdown = 60;

function settime(obj) { //发送验证码倒计时
	//发送验证码倒计时
	if (countdown == 0) {
		$(obj).removeClass("disabledBtn")
		$(obj).attr("style", "background: ");
		$(obj).attr("isSend", "0");
		$(obj).text("获取验证码");
		countdown = 60;
		return;
	} else {
		$(obj).addClass("disabledBtn")
		$(obj).attr("style", "background: gray;");
		$(obj).attr("isSend", "1");
		$(obj).text("重新发送(" + countdown + ")");
		countdown--;
	}
	setTimeout(function () {
		settime($(obj))
	}, 1000)
}

//确认绑卡
function saveInfo() {
	var ligerForm = liger.get("ins_cfg_info_edit_form");
    if (!ligerForm.valid()) {
        top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
        return false; //验证不通过，不执行以下代码
    }
    var data = ligerForm.getData();
	if(!$("#bkCd").val()){
		top.$.ligerDialog.SQalert({content: "请选择开户银行！", SQ_type: "error"});
		return false;
	}
    if(!$("#accNo").val()){
        top.$.ligerDialog.SQalert({content: "银行账号不能为空，请补充", SQ_type: "error"});
        return false;
    }
    if(!$("#mp").val()){
        top.$.ligerDialog.SQalert({content: "预留手机号不能为空，请补充！", SQ_type: "error"});
        return false;
    }
    if(!$("#verificationCode").val()){
        top.$.ligerDialog.SQalert({content: "验证码不能为空，请补充！", SQ_type: "error"});
        return false;
    }
	data["bkCd"] = liger.get("bkCd").selectedValue;
	data["bkNm"] = liger.get("bkCd").selectedText;
    data["cstAccInfoId"] = $("#cstAccInfoId").val();
    data["prjId"] = $("#prjId").val();
    data["cstId"] = $("#cstId").val();
    data["cstNm"] = $("#cstNm").val();
    data["fundRasInsId"] = $("#fundRasInsId").val();
    data["certNo"] = $("#certNo").val();
	data["accNo"] =  $("#accNo").val();
    data["mp"] = $("#mp").val();
    data["verificationCode"] = $("#verificationCode").val();//验证码
    data["uniqueCode"] = $("#uniqueCode").val();//唯一码
	var url = '<%=path%>/institution/shnsbank/exchangeCardSave.do';
    var wait_dialog;
    $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        },
        success: function (msg) {
            wait_dialog.close();
            if (msg.success == 1) {
            	//不关闭当前页面,刷新父页面
                 parent.grid.reload();
				$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				frameElement.dialog.close();

            } else {
            	if (msg.success == 2){
            		parent.grid.reload();//刷新父页面
            	}
				UIUtils.alertErrorHold1(msg.info);

            }
        },
		error:function(e){
			wait_dialog.close();
			// $.ligerDialog.SQalert({content:"系统异常！", SQ_type: "error"});
			UIUtils.alertErrorHold1("系统异常！");
		}
    });
}

</script>

</body>
</html>